//package org.example.sys.cfg;
//
//import com.fasterxml.jackson.annotation.JsonInclude;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.context.ApplicationContext;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.http.converter.HttpMessageConverter;
//import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
//import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
//import org.springframework.web.cors.CorsConfiguration;
//import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
//import org.springframework.web.filter.CorsFilter;
//import org.springframework.web.servlet.config.annotation.EnableWebMvc;
//import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
//import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
//import java.util.List;
//
//
//@Configuration
//@EnableWebMvc
//public class WebConfigure implements WebMvcConfigurer {
//
//    @Autowired
//    private ApplicationContext applicationContext;
//
//    @Override
//    public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
//        Jackson2ObjectMapperBuilder json = Jackson2ObjectMapperBuilder.json();
//        json.applicationContext(this.applicationContext);
//        json.serializationInclusion(JsonInclude.Include.NON_NULL);
//        converters.removeIf(f -> f.getClass() == MappingJackson2HttpMessageConverter.class);
//        converters.add(new MappingJackson2HttpMessageConverter(json.build()));
//    }
//
//    @Override
//    public void addResourceHandlers(ResourceHandlerRegistry registry) {
//        //配置静态资源处理
//        registry.addResourceHandler("/**")
//                .addResourceLocations("resources/", "static/", "public/",
//                        "META-INF/resources/")
//                .addResourceLocations("classpath:resources/", "classpath:static/",
//                        "classpath:public/", "classpath:META-INF/resources/")
//                .addResourceLocations("file:C://Users//Chris//IdeaProjects//book//public");
//        WebMvcConfigurer.super.addResourceHandlers(registry);
//    }
//
//    @Bean
//    public CorsFilter corsFilter() {
//        //1. 添加 CORS配置信息
//        CorsConfiguration config = new CorsConfiguration();
//        //放行哪些原始域
//        config.addAllowedOrigin("*");
//        //是否发送 Cookie
//        config.setAllowCredentials(true);
//        //放行哪些请求方式
//        config.addAllowedMethod("*");
//        //放行哪些原始请求头部信息
//        config.addAllowedHeader("*");
//        //暴露哪些头部信息
//        config.addExposedHeader("*");
//        //2. 添加映射路径
//        UrlBasedCorsConfigurationSource corsConfigurationSource = new UrlBasedCorsConfigurationSource();
//        corsConfigurationSource.registerCorsConfiguration("/**",config);
//        //3. 返回新的CorsFilter
//        return new CorsFilter(corsConfigurationSource);
//    }
//}
